package cn.edu.wynu.d4_inner_class4;

import javax.swing.*;
import java.awt.event.ActionEvent;

public class Test {
    public static void main(String[] args) {
        // 拓展：匿名内部类在开发中的实际应用场景
        // GUI编程，桌面程序
        // 1、创建窗口
        JFrame win = new JFrame("登录界面");
        JPanel panel = new JPanel();
        win.add(panel);

        // 2、添加按钮
        JButton btn = new JButton("登录");
        panel.add(btn);

        // 3、给按钮添加单击事件监听器
        /*
        btn.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(win, "登录成功");

            }
        });
        */
        // 匿名内部类最终的核心目的是：简化代码
        btn.addActionListener (e -> JOptionPane.showMessageDialog(win, "登录成功"));

        win.setSize(400,400);
        win.setLocationRelativeTo(null);
        win.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        win.setVisible(true);
    }
}
